<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>1.localStorage</title>
  </head>
  <body>
    <h1>localStorage</h1>
    <button onclick="save()">存数据</button>
    <button onclick="read()">读数据</button>
    <button onclick="update()">更新数据</button>
    <button onclick="del()">删除数据</button>
    <button onclick="clean()">清空数据</button>

    <script type="text/javascript" >
      // 存储
      function save(){
        let luo = {name:'罗先森',age:99}
        localStorage.setItem('a',JSON.stringify(luo))
      }
      // 读取
      function read(){
        let result = localStorage.getItem('a')
        console.log(JSON.parse(result))
      }
      // 更新
      function update(){
        let jing = {name:'静静',age:30}
        localStorage.setItem('a',JSON.stringify(jing))
      }
      // 删除
      function del(){
        localStorage.removeItem('a')
      }
      // 清空
      function clean(){
        localStorage.clear()
      }
    </script>
  </body>
</html>